From: emellor@ewan Date: Fri, 30 Sep 2005 09:48:49 +0000 (+0100) Subject: Added DevController.configuration and configurations methods. These parse the X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~16763^2~73 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22?a=commitdiff_plain;h=a4db84d76c3f31b8549df00bc19964a0696e1ea8;p=xen.git Added DevController.configuration and configurations methods. These parse the store for the current device configuration, and convert it back into the s-expression used in the config files and the save files. This means that we can bring the devices up properly on restore. Signed-off-by: Ewan Mellor --- diff --git a/tools/python/xen/xend/server/DevController.py b/tools/python/xen/xend/server/DevController.py index 0130075ac3..942efd46b4 100644 --- a/tools/python/xen/xend/server/DevController.py +++ b/tools/python/xen/xend/server/DevController.py @@ -75,12 +75,28 @@ class DevController: """ frontpath = self.frontendPath(devid) - backpath = xstransact.Read("%s/backend" % frontpath) + backpath = xstransact.Read(frontpath, "backend") xstransact.Remove(frontpath) xstransact.Remove(backpath) + def configurations(self): + return map(lambda x: self.configuration(int(x)), + xstransact.List(self.frontendRoot())) + + + def configuration(self, devid): + """@return an s-expression giving the current configuration of the + specified device. This would be suitable for giving to {@link + #createDevice} in order to recreate that device.""" + + backdomid = int(xstransact.Read(self.frontendPath(devid), + "backend-id")) + + return [self.deviceClass, ['backend', backdomid]] + + def sxprs(self): """@return an s-expression describing all the devices of this controller's device-class. @@ -150,6 +166,12 @@ class DevController: raise + def readBackend(self, devid, *args): + frontpath = self.frontendPath(devid) + backpath = xstransact.Read(frontpath, "backend") + return xstransact.Read(backpath, *args) + + ## private: def writeDetails(self, config, devid, backDetails, frontDetails): @@ -211,4 +233,5 @@ class DevController: def frontendMiscPath(self): - return "%s/device-misc/%s" % (self.vm.getPath(), self.deviceClass) + return "%s/device-misc/%s" % (self.vm.getPath(), + self.deviceClass) diff --git a/tools/python/xen/xend/server/blkif.py b/tools/python/xen/xend/server/blkif.py index 51ca12b131..bfc559f74f 100755 --- a/tools/python/xen/xend/server/blkif.py +++ b/tools/python/xen/xend/server/blkif.py @@ -40,14 +40,15 @@ class BlkifController(DevController): def getDeviceDetails(self, config): """@see DevController.getDeviceDetails""" - typedev = sxp.child_value(config, 'dev') - if re.match('^ioemu:', typedev): + dev = sxp.child_value(config, 'dev') + if re.match('^ioemu:', dev): return (0,{},{}) - devid = blkif.blkdev_name_to_number(sxp.child_value(config, 'dev')) + devid = blkif.blkdev_name_to_number(dev) (typ, params) = string.split(sxp.child_value(config, 'uname'), ':', 1) - back = { 'type' : typ, + back = { 'dev' : dev, + 'type' : typ, 'params' : params } @@ -57,3 +58,22 @@ class BlkifController(DevController): front = { 'virtual-device' : "%i" % devid } return (devid, back, front) + + + def configuration(self, devid): + """@see DevController.configuration""" + + result = DevController.configuration(self, devid) + + (dev, typ, params, ro) = self.readBackend(devid, + 'dev', 'type', 'params', + 'read-only') + + result.append(['dev', dev]) + result.append(['uname', typ + ":" + params]) + if ro: + result.append(['mode', 'r']) + else: + result.append(['mode', 'w']) + + return result diff --git a/tools/python/xen/xend/server/netif.py b/tools/python/xen/xend/server/netif.py index 127529ad56..d195363ba5 100755 --- a/tools/python/xen/xend/server/netif.py +++ b/tools/python/xen/xend/server/netif.py @@ -23,10 +23,14 @@ import os from xen.xend import sxp +from xen.xend import XendRoot from xen.xend.server.DevController import DevController +xroot = XendRoot.instance() + + class NetifController(DevController): """Network interface controller. Handles all network devices for a domain. """ @@ -38,9 +42,6 @@ class NetifController(DevController): def getDeviceDetails(self, config): """@see DevController.getDeviceDetails""" - from xen.xend import XendRoot - xroot = XendRoot.instance() - def _get_config_ipaddr(config): val = [] for ipaddr in sxp.children(config, elt='ip'): @@ -68,3 +69,22 @@ class NetifController(DevController): 'mac' : mac } return (devid, back, front) + + + def configuration(self, devid): + """@see DevController.configuration""" + + result = DevController.configuration(self, devid) + + (script, ip, bridge, mac) = self.readBackend(devid, + 'script', 'ip', 'bridge', + 'mac') + + result.append(['script', + script.replace(xroot.network_script_dir + os.sep, "")]) + if ip: + result.append(['ip', ip.split(" ")]) + result.append(['bridge', bridge]) + result.append(['mac', mac]) + + return result